package com.yaorange.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class SqlSessionUtil {
    private static InputStream resourceAsStream;
    private static SqlSessionFactory sqlSessionFactory;
    private static SqlSession sqlSession;
    public static SqlSession getSqlSession() throws IOException {
        resourceAsStream = Resources.getResourceAsStream("SqlMapConfig.xml");
        //加载mybatis的核心配置文件获取SqlSessionFactory
      sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        sqlSession = sqlSessionFactory.openSession();
        return sqlSession;
    }
}
